#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int longestSubarray(vector<int>& nums) {
        int l = 0, r = 0;
        int n = nums.size();
        int cnt = 0;
        int ret = 0;
        while (r < n)
        {
            if (nums[r] == 0) cnt++;

            while (cnt > 1)
            {
                if (nums[l] == 0) cnt--;
                l++;
            }

            r++;
            ret = max(ret, r - l);
        }
        return ret - 1;
    }
};